package com.ysm.smfu.adapter;

import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;

import com.ysm.smfu.R;
import com.ysm.smfu.utils.UIUtils;

/**
 * Created by Administrator on 2016/11/7.
 */
public class MyPagerAdapter extends PagerAdapter {

    private final String[] names1;
    private final String[] ids2;
    private final String[] ids1;
    private final int[] ims2;
    private final int[] ims1;
    private final String[] names2;
    private final FragmentActivity fragmentActivity;
    private MyGridAdapter adapter;

    public MyPagerAdapter(String[] category_name1, String[] category_name2, int[] category_ims1, int[] category_ims2, String[] category_id1, String[] category_id2,
                         FragmentActivity activity) {
        names1 = category_name1;
        names2 = category_name2;
        ims1 = category_ims1;
        ims2 = category_ims2;
        ids1 = category_id1;
        ids2 = category_id2;
        fragmentActivity =activity;
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = View.inflate(UIUtils.getContext(), R.layout.item_category_viewpager, null);
        GridView gridView = (GridView) view.findViewById(R.id.grd_category);
        if (position == 0) {
            adapter = new MyGridAdapter(names1, ims1, ids1,fragmentActivity);
            gridView.setAdapter(adapter);
        }
        if (position == 1)
            adapter = new MyGridAdapter(names2, ims2, ids2, fragmentActivity);
        gridView.setAdapter(adapter);
        container.addView(view);
        return view;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
        container.removeView((View) object);
    }
}

